package cj.web.marriageSC.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriageSC.domain.SCGoods;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SCGoodsDAO{
	
    @SQL("select * from SCGoods where id=:1")
    SCGoods queryById(int id);
    
    @ReturnGeneratedKeys
    @SQL("INSERT INTO SCGoods (sellerId,categoryId,title,descs,image,status,type,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.sellerId,:t.categoryId,:t.title,:t.descs,:t.image,:t.status,:t.type,:t.deleteFlag,NOW(),:t.createUser,NOW(),:t.updateUser)")
    int create(@SQLParam("t") SCGoods sCGoods);
	
	@SQL("UPDATE SCGoods SET title=:t.title,descs=:t.descs,image=:t.image,type=:t.type,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") SCGoods sCGoods);
    
    @SQL("UPDATE SCGoods SET deleteFlag=0,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
    void deleteById(@SQLParam("t") SCGoods sCGoods);

    @SQL("select a.id,b.name as sellerName,a.type,c.name as categoryName,a.title,a.orignPriceRange,a.priceRange,a.status from SCGoods a JOIN SCSeller b on a.sellerId=b.id and b.deleteFlag=1 JOIN SCCategory c on a.categoryId=c.id and c.deleteFlag=1 where a.deleteFlag=1 #if(:t.sellerId!=-1){ and a.sellerId=:t.sellerId } #if(:t.title!=''){ and a.title like '%##(:t.title)%' } order by a.sellerId,a.status desc,a.stickAt desc LIMIT :t.start,:t.length")
	List<Map> queryBySellerId(@SQLParam("t")SCGoods goods);

    @SQL("select count(0) from SCGoods a JOIN SCSeller b on a.sellerId=b.id and b.deleteFlag=1 JOIN SCCategory c on a.categoryId=c.id and c.deleteFlag=1 where a.deleteFlag=1 #if(:t.sellerId!=-1){ and a.sellerId=:t.sellerId } #if(:t.title!=''){ and a.title like '%##(:t.title)%' }")
	int sizeBySellerId(@SQLParam("t")SCGoods goods);

    @SQL("UPDATE SCGoods SET status=:t.status,updateAt=NOW(),updateUser=:t.updateUser WHERE id=:t.id")
	void updownById(@SQLParam("t") SCGoods goods);

    @SQL("UPDATE SCGoods SET stickAt=NOW() WHERE id=:1")
	void stick(int id);

    @SQL("UPDATE SCGoods SET orignPriceRange=:2,priceRange=:3 WHERE id=:1")
	void updatePriceRange(int goodsId, String origPriceRange,
			String discntPriceRange);

    @SQL("delete from SCGoodsBanner where goodsId=:1")
	void delBannerByGoodsId(int goodsId);

    @SQL("insert into SCGoodsBanner(path, goodsId) values(:1, :2)")
	void createBanner(String path, int goodsId);

    @SQL("select id,path from SCGoodsBanner where goodsId=:1")
	List<Map> getBannerByGoodsId(int goodsId);
}